package dbPhase.hypeerweb;

import static org.junit.Assert.*;

import java.util.HashSet;

import org.junit.Test;

public class HyPeerWebDatabaseTest {

	@Test
	public void testSaveNodes() {
		fail("Not yet implemented");
	}

	@Test
	public void testGetNode() {
		HyPeerWebDatabase.initHyPeerWebDatabase("Testdb.db");
		HyPeerWebDatabase testhypeerwebdatabase = HyPeerWebDatabase.getSingleton();
		SimplifiedNodeDomain node0 = testhypeerwebdatabase.getNode(0);
		SimplifiedNodeDomain node1 = testhypeerwebdatabase.getNode(1);
		SimplifiedNodeDomain node2 = testhypeerwebdatabase.getNode(2);
		SimplifiedNodeDomain node3 = testhypeerwebdatabase.getNode(3);
		SimplifiedNodeDomain node4 = testhypeerwebdatabase.getNode(4);
		System.out.println("Trying to get nonexistant Node");
		SimplifiedNodeDomain node5 = testhypeerwebdatabase.getNode(5);

		assertTrue(node5 == null);

		assertTrue(node0.webId == 0);
		assertTrue(node0.height == 1);
		assertTrue(node1.webId == 1);
		assertTrue(node1.height == 1);
		assertTrue(node2.webId == 2);
		assertTrue(node2.height == 2);
		assertTrue(node3.webId == 3);
		assertTrue(node3.height == 2);
		assertTrue(node4.webId == 4);
		assertTrue(node4.height == 2);

		assertTrue(node0.surrogateFold == 1);
		assertTrue(node1.fold == 2);
		assertTrue(node2.surrogateFold == 0);
		assertTrue(node3.fold == 0);
		assertTrue(node4.surrogateFold == 0);

		assertTrue(node1.inverseSurrogateFold == 0);

		assertTrue(node0.neighbors.contains(1));
		assertTrue(node0.neighbors.contains(2));
		assertTrue(node0.neighbors.contains(4));

		HashSet<Integer> downs = node1.downPointers;  // neighbors who are surrogates

		assertTrue(downs.contains(2));
		assertTrue(downs.contains(3));

		HashSet<Integer> ups = node2.upPointers;  // neighbors who are surrogates

		assertTrue(ups.contains(1));

		ups = node3.upPointers;  // neighbors who are surrogates

		assertTrue(ups.contains(1));

	}

	@Test
	public void testGetSingleton() {

		fail("Not yet implemented");
	}

	@Test
	public void testInitHyPeerWebDatabase() {
		fail("Not yet implemented");
	}

}
